<?php

use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{

    private $class;
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->readClass();
        if(!empty($this->class)) {
            foreach($this->class as $val) {
                if($val == 'DatabaseSeeder') continue;
                $this->call($val);
            }

        }

        exit;
    }

    private function readClass() {
        $dir = __DIR__;
        $handler = opendir($dir);
        while( ($filename = readdir($handler)) !== false )
        {
            //略过linux目录的名字为'.'和‘..'的文件
            if($filename != '.' && $filename != '..')
            {
                //输出文件名
                $filename = explode(".php",$filename);
                $filename = $filename[0];
                $this->class[] = $filename;
            }
        }
    }
}
